package com.foreknow.demo12;

/**
 * @author shkstart
 * @create 2021-08-02 10:06
 */

import java.util.*;

/**
 * 向List中添加Map，Map中有两个Student类型的对象
 */
public class MapTest {
    public static void main(String[] args) {
//        List<Map<String,Student>> list=new ArrayList<>();
//        Map<String,Student> map1=new HashMap<>();
//        Map<String,Student> map2=new HashMap<>();
//        Map<String,Student> map3=new HashMap<>();
//        list.add(map1);
//        list.add(map2);
//        list.add(map3);
//        Student s1=new Student("1","aaa",20);
//        Student s2=new Student("2","bbb",21);
//        Student s3=new Student("3","ccc",22);
//        Student s4=new Student("4","ddd",23);
//        Student s5=new Student("5","eee",23);
//        Student s6=new Student("6","fff",23);
//        map1.put("1",s1);
//        map1.put("2",s2);
//        map2.put("3",s3);
//        map2.put("4",s4);
//        map3.put("5",s5);
//        map3.put("6",s6);
//
//
//        for (int i = 0; i < list.size(); i++) {
//            Map<String, Student> sSMap = list.get(i);
//            Set<Map.Entry<String, Student>> entries = sSMap.entrySet();
//            Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
//            while (iterator.hasNext()){
//                Map.Entry<String, Student> next = iterator.next();
//                String key = next.getKey();
//                Student value = next.getValue();
//                System.out.println(key+"--------"+ value);
//            }
//        }

        List<Map<Integer,Student>> list1=new ArrayList<>();

        Map<Integer,Student> map1=new HashMap<>();
        Map<Integer,Student> map2=new HashMap<>();
        Map<Integer,Student> map3=new HashMap<>();
        list1.add(map1);
        list1.add(map2);
        list1.add(map3);
        Student s1=new Student("1","aaa",20);
        Student s2=new Student("2","bbb",21);
        Student s3=new Student("3","ccc",22);
        Student s4=new Student("4","ddd",23);
        Student s5=new Student("5","eee",23);
        Student s6=new Student("6","fff",23);
        map1.put(1,s1);
        map1.put(2,s2);
        map2.put(3,s3);
        map2.put(4,s4);
        map3.put(5,s5);
        map3.put(6,s6);

        for (int i = 0; i < list1.size(); i++) {
            Map<Integer,Student> ss1=list1.get(i);
            Set<Map.Entry<Integer, Student>> entries = ss1.entrySet();
            Iterator<Map.Entry<Integer, Student>> iterator = entries.iterator();
            while (iterator.hasNext()){
                Map.Entry<Integer, Student> next = iterator.next();
                System.out.println(next.toString());
            }

        }

    }


}
